/**
 * Created by Administrator on 2017/3/4 004.
 */
var dinshiqi;
window.onload = function () {
    var pid = document.getElementById('pid');
    var pid1 = document.getElementById('pid1');
    var pid2 = document.getElementById('pid2');
    var btn1 = document.getElementById('btn1');
    var btn2 = document.getElementById('btn2');
    dinshiqi = setInterval(function () {
        num = Math.floor(Math.random()*10)+1;
        num1 = Math.floor(Math.random()*10)+1;
        num2 = Math.floor(Math.random()*10)+1;
        pid.innerHTML = num;
        pid1.innerHTML = num1;
        pid2.innerHTML = num2;
    },500);
    // 开始游戏
    btn1.addEventListener('click',fun1);
    function fun1() {
        clearInterval(dinshiqi);
        //获取按钮的勾选值
        var obj = document.getElementsByName("test");
        check_val = [];
        for(k in obj){
            if(obj[k].checked)
                check_val.push(obj[k].value);
        }
        if (check_val[0] == num && check_val[1] == num1 && check_val[2] == num2) {
            alert("恭喜你中奖了！");
        }else {
            alert("号码不对，再来一次？");
        }

    }
    btn2.addEventListener('click',function () {
        //在开始游戏之前先清除之前的定时器
        clearInterval(dinshiqi);
        dinshiqi = setInterval(function () {
            num = Math.floor(Math.random()*10)+1;
            num1 = Math.floor(Math.random()*10)+1;
            num2 = Math.floor(Math.random()*10)+1;
            pid.innerHTML = num;
            pid1.innerHTML = num1;
            pid2.innerHTML = num2;
        },500);

    });
}